import { defineStore } from "pinia"
import { darkTheme } from 'naive-ui'
import type { GlobalTheme } from 'naive-ui'
import { dateZhCN, zhCN } from 'naive-ui'
import type { NDateLocale, NLocale } from 'naive-ui'

// @ts-ignore
export const useSystemStore = defineStore("system", {
    state: () => {
      return {
        isDark: false as boolean,
        theme : null as GlobalTheme | null,
        language: "zh-CN",
        locale: null as NLocale | null,
        dateLocale: null as NDateLocale | null,
      };
    },
    actions: {
        changeTheme() {
          this.isDark = !this.isDark;
          this.theme = this.isDark ? darkTheme : null;
        },
        changeLanguage(language: string){
          if(language.toLowerCase() === "en-us"){
            this.locale = null;
            this.dateLocale = null;
            this.language = "en-US";
          }else if(language.toLowerCase() === "zh-cn"){
            this.locale = zhCN;
            this.dateLocale = dateZhCN;
            this.language = "zh-CN";
          }
        },
    },
    persist: {
      enabled: true,
      strategies: [
        {
          key: "nuxt-system",
          storage: process.client ? localStorage : null,
        },
      ],
    },
  });